﻿namespace KeyStone.EventHub
{
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading;

   /// <summary>
   /// Class Payload.
   /// </summary>
   public abstract class Payload
   {
      /// <summary>
      /// Gets or sets the synchronize.
      /// </summary>
      /// <value>The synchronize.</value>
      public EventWaitHandle Sync { get; set; }

      /// <summary>
      /// Initializes a new instance of the <see cref="Payload"/> class.
      /// </summary>
      public Payload()
      {

      }

      /// <summary>
      /// Sets this instance.
      /// </summary>
      public void Set()
      {
         if (Sync == null) return;
         Sync.Set();
      }

      /// <summary>
      /// Resets this instance.
      /// </summary>
      public void Reset()
      {
         if (Sync == null) return;
         Sync.Reset();
      }

      /// <summary>
      /// Waits this instance.
      /// </summary>
      public void Wait()
      {
         if (Sync == null) return;
         Sync.WaitOne();
      }

      /// <summary>
      /// Waits the specified time.
      /// </summary>
      /// <param name="time">The time.</param>
      public void Wait(TimeSpan time)
      {
         if (Sync == null) return;
         if (Sync == null) return;
         Sync.WaitOne(time.Milliseconds);
      }
   }
}
